//
//  UserModule.swift
//  Kool Car
//
//  Created by huangweiqiang on 2021/12/16.
//

import UIKit

class UserModule {
    static let shared = UserModule()
    var token: String? {
        didSet {
            if token != nil {
                let ud = UserDefaults.standard
                ud.set(token!, forKey: "token")
                ud.synchronize()
            }
        }
    }
    
    var loginAccount: String? {
        didSet {
            if loginAccount != nil {
                UserDefaults.standard.setValue(loginAccount, forKeyPath: "login_account")
            }
        }
    }
    
    var loginPwd: String? {
        didSet {
            if loginPwd != nil {
                UserDefaults.standard.setValue(loginPwd, forKeyPath: "login_pwd")
            }
        }
    }
    
    var isLogined: Bool? {
        didSet {
            if isLogined != nil {
                UserDefaults.standard.setValue(isLogined, forKeyPath: "login_status")
            }
        }
    }
    
    init() {
        let userDefaults = UserDefaults.standard
        token = userDefaults.string(forKey: "token")
        isLogined = userDefaults.bool(forKey: "login_status")
        loginAccount = userDefaults.string(forKey: "login_account")
        loginPwd = userDefaults.string(forKey: "login_pwd")
    }
}
